package com.adou.multi.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
	private static final String API_TITLE = "MULTI-TENANT接口文档";
	private static final String API_DESCRIPTION = "文档说明";
	private static final String API_VERSION = "0.0.1";
	private static final String API_PACKAGE = "com.adou.multi.controller";
	
	private static final String REFERENCE = "api_oauth";
	
	@Bean
	public Docket api(){
		List<Parameter> headers = new ArrayList<>();
		ParameterBuilder ticketPar = new ParameterBuilder();
		
		headers.add(ticketPar.name("X-TENANT_ID").description("租户id")
				.modelRef(new ModelRef("string")).parameterType("header")
				.required(false).build());
		
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage(API_PACKAGE)).paths(PathSelectors.any())
				.build().globalOperationParameters(headers);
		
	}
	
	private ApiInfo apiInfo(){
		return new ApiInfoBuilder().title(API_TITLE).description(API_DESCRIPTION).version(API_VERSION).build();
	}
	
	
	
	
	
	
	
	
	
}
